home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 4.3 KB | 135 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- package mixer.display;
-
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
-
- import quicktime.*;
- import quicktime.app.audio.*;
- import quicktime.std.movies.media.*;
-
- import mixer.mc.*;
-
- /** This is our class to display the controls for a typical sound (or music) track
- * in a movie. It permits all controls because all of the controls are valid
- * settings for a sound track.
- */
- public class SoundTrackDisplay extends MasterDisplay {
- private boolean soloed; // true = another channel has turned this one off
- private SoloableChannels parent;
-
- /** The constructor needs to know which SoloableChannel object made it (for the solo
- * stuff) and which MixerComponents it's making the display for.
- * @param par the SoloableChannels object that created this object
- * @param media the MixerComponents object to make the display for
- */
- public SoundTrackDisplay (SoloableChannels par, MixerComponents media) throws QTException {
- this (par, media, true, true, true, true);
- }
-
- protected SoundTrackDisplay (SoloableChannels par, MixerComponents media, boolean mute, boolean solo, boolean balance, boolean volume) throws QTException {
- super (media, mute, solo, balance, volume);
-
- parent = par;
- soloed = false;
- }
-
- /* This method adds the action listener appropriate for SoundTrackDisplays to the
- * solo button it gets as an argument. Note that the code actually must call the
- * SoloableChannels parent object to perform the solo operation.
- */
- void addSoloAction (JCheckBox b) {
- b.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- if (((JCheckBox) e.getSource()).isSelected()) {
- if (false == muteButton.isSelected())
- mixer.getMaster().setMuted(false);
- parent.setSolo(true);
- }
- else {
- if (false == soloed && false == muteButton.isSelected())
- mixer.getMaster().setMuted(false);
- parent.setSolo(false);
- }
- }
- catch (QTException ex) {
- throw new QTRuntimeException (ex);
- }
- }
- });
- }
-
- /* This method adds the ActionListener needed for mute buttons. */
- void addMuteAction (JCheckBox b) {
- try {
- b.setSelected (mixer.getMaster().isMuted());
- b.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- if (((JCheckBox) e.getSource()).isSelected())
- mixer.getMaster().setMuted(true);
- else
- if (false == soloed || true == soloButton.isSelected())
- mixer.getMaster().setMuted(false);
- }
- catch (QTException ex) {
- throw new QTRuntimeException (ex);
- }
- }
- });
- } catch (QTException e) {
- throw new QTRuntimeException (e);
- }
- }
-
- /* This method adds the ActionListener needed for balance sliders. */
- void addBalanceAction (JSlider b) {
- try {
- b.setValue((int)(((ExtendedAudioSpec)mixer.getMaster()).getBalance() * 100.0F));
- b.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- try {
- JSlider source = (JSlider) e.getSource();
- Integer tmp = new Integer(source.getValue());
- float p = tmp.floatValue();
- p = p / 100.0F;
- ((ExtendedAudioSpec) mixer.getMaster()).setBalance(p);
- }
- catch (QTException ex) {
- throw new QTRuntimeException (ex);
- }
- }
- });
- } catch (QTException e) {
- throw new QTRuntimeException (e);
- }
- }
-
- /* This method is invoked by the SoloableChannels parent object whenever
- * a channel (including this one) changes its solo state. The argument is
- * a count of the number of channels currently holding the solo state.
- */
- void doSolo(int count) throws QTException {
- if (false == soloButton.isSelected()) { // this channel is not solo
- if (count > 0) { // another channel is solo
- mixer.getMaster().setMuted(true);
- soloed = true;
- }
- else { // no channels are solo
- if (false == muteButton.isSelected()) // this channel is not muted
- mixer.getMaster().setMuted(false); // so let it play
- soloed = false;
- }
- }
- }
- }
-